package com.example.demo.model;

import com.example.demo.dao.entity.UserInfo;
import com.example.demo.util.serializer.CustomDateDeserializer;
import com.example.demo.util.serializer.CustomDateSerializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description:用户信息
 * @author: jacheut
 * @create: 2018-07-05 16:46
 **/
@Data
public class UserInfoVo {
    private Integer id;

    private Integer userId;
    /**
     * 账号
     */
    private String username;
    /**
     * 名字
     */
    private String name;
    /**
     * 密码
     */
    private String password;
    /**
     * md5密码盐
     */
    private String salt;
    /**
     * 联系电话
     */
    private String phone;
    /**
     * 备注
     */
    private String tips;
    /**
     * 状态 1:正常 2:禁用
     */
    private Integer state;
    /**
     * 创建时间
     */
    @JsonSerialize(using = CustomDateSerializer.class)
    @JsonDeserialize(using = CustomDateDeserializer.class)
    private Date createdTime;
    /**
     * 更新时间
     */
    private Date updatedTime;

    public static List<UserInfoVo> convertUserInfoList(List<UserInfo> userInfoList) {
        List<UserInfoVo> userInfoVos = new ArrayList<>();
        userInfoList.stream().forEach(userInfo ->
        {
            UserInfoVo userInfoVo = new UserInfoVo();
            BeanUtils.copyProperties(userInfo, userInfoVo);
            userInfoVos.add(userInfoVo);
        });
        return userInfoVos;
    }
}
